package com.zhanghp.class020;

/**
 * @author zhanghp
 * @since 2024/3/4 15:09
 */
// 用这个例子讲解递归如何执行
public class GetMaxValue {

    public static int maxValue(int[] arr){
        return f(arr, 0, arr.length - 1);
    }

    public static int f(int[] arr, int l, int r){
        if (l == r) {
            return arr[l];
        }
        int mid = (l + r) / 2;
        int lmax = f(arr, l, mid);
        int rmax = f(arr, mid + 1, r);
        return Math.max(lmax, rmax);
    }

    public static void main(String[] args) {
        int[] arr = { 3, 8, 9, 6, 4, 5, 1, 2 };
        System.out.println("数组最大值 : " + maxValue(arr));
    }
}
